Stock Exchange Visualizations
in Python
August 21, 2022
Philippe Lambot
In this project, I will focus on interactive stock quote visualizations in Python.
This project stands in my GitHub account, with other projects in visualization, for instance in NPS, and in Machine Learning.
Data have been extracted from Yahoo! Finance . They relate to the stocks of eight financial institutions over the period since 2000. Any usage of this document must comply with requirements issued by Yahoo! Finance.
The eight financial institutions are listed below with their names and ticker symbols.
As can be seen from the table above, special attention has been paid to the international diversity of the financial institutions chosen. They originate from China, France, Germany, Japan, the Netherlands, the United Kingdom, or the United States. These financial institutions have been picked up using Yahoo! Finance and LexisNexis .
All data consist of stock quotes from Yahoo! Finance . They cover the period from the beginning of 2000 until the end of July 2022. Three institutions have partial data: MUFG (data starting on April 2, 2001), BNPQY (June 5, 2003), and BACHY (December 29, 2009). Stock quotes originate from the NYSE except for BACHY and BNPQY (OTC). They are all denominated in US $.
The y-axis scale is determined by the sharp drop of Citigroup's stock price. Consequently, let's split the eight lines into three subgroups in accordance with the range of closinng price variations over 20 years. In the first subgroup, we'll keep just Citigroup, in the second subgroup BCS, BNPQY, DB, ING, JPM, and in the third subgroup BACHY and MUFG.
Let's start with Citigroup on its own.
Let's draw line charts for these five financial institutions. Each institution will be dealt with separately but all will have the same y-axis scale to foster comparability.
And now both financial institutions with lower closing price fluctuations in absolute value: BACHY and MUFG.
Investopedia start one of their articles with a humbling remark: "Candlestick charts originated in Japan over 100 years [...] a Japanese man named Homma discovered that [...] the markets were strongly influenced by the emotions of traders."
Candlestick charts summarize information about open , high, low, and close prices on the chosen temporal basis. Let's apply that to JPM and BACHY.
BACHY is being displayed on the same period.
In this section, we'll use data about closing prices, "high" prices, and "low" prices, on a daily basis. These data will be used to build up Bollinger Bands®.
As stated in Investopedia, "Bollinger Bands® are a technical analysis tool developed by John Bollinger for generating oversold or overbought signals..
The Bollinger Bands® are comprised of three lines:
The simple moving average is typically a 20-day simple moving average of the typical price, that is to say the mean of high price, low price, and closing price of a stock on a daily basis, which will be done in this presentation. It could also be the 20-day simple moving average of the closing price itself. The upper band is typically two standard deviations of the typical price above the middle band. The lower band is typically two standard deviations below the middle band. A candlestick graph can be inserted.
Actually, Bollinger issued 22 rules to follow when using the bands in practice as a trading system.
Let's draw Bollinger Bands® for BNPQY's stock since June 2022. BNP Paribas SA is the biggest bank in Europe on the basis of assets as of the end of 2020, as shown by InsiderIntelligence.
Let's switch to the Dutch financial institution ING Groep N.V. with Bollinger Bands® since the beginning of 2022.
A return is the change in price of an asset, investment, or project over time, which may be represented in terms of price change or percentage change. . We will work on returns from stocks expressed in percentage to ensure better comparability between financial institutions.
January 20, 2019 was [Inauguration Day](https://www.investopedia.com/ask/answers/101314/where-was-dow-jones-when-obama-took-office.asp). How much was the sharpest drop in closing price on 2009-01-20?
In order to retrieve some visual evidence about realtionships between the return time series of the eight financial institutions, let's draw a scatter plot matrix, which is comprised of 56 bilateral scatter plots. For readability purposes, the period has been limited to the third quarter of 2022. Also for readability purposes, the graphs on the diagonal, which could have been histograms, have been removed.
On the basis of the graph above, a relatively high positive correlation can be expected between ING and DB because there are relatively few points in the second and fourth quadrants. A quadrant is very simply defined by the Collins Dictionary as being "any of the four sections into which a plane is divided by two coordinate axes". Points in the second and fourth quadrants point towards negative correlation, points in the first and third quadrants towards positive correlation.
When points are spread in the four quadrants, this points towards low correlation. This looks like it between MUFG and JPM.
We will see that both statements are corroborated by correlation coefficients. But in most cases, the scatter plots above do not give any clear visual indication about correlation because most points are amalgamated and density does not show clearly. Consequently, let's switch to correlation matrices, first over the same period, namely June-August 2022, and then over a much longer period.
As expected on the basis of some scatter plots, the correlation coefficient between ING and DB is positive and rather important, namely +0.8. On the contrary, the correlation coefficient between MUFG and JPM is rather low, with a value of 0.3, in the line of scatter plots.
Let's switch to a much longer period, namely from 2010 until 2022.
The picture is completely different if we broaden the picture and encompass the period since 2010.
When switching from June-August 2022 to 2010-2022, the correlation coefficient between DB and ING moves from highly positive to slightly negative; there is a similar move between on the one hand DB and on the other hand Citigroup and JPM.
The correlation coefficient between BCS and JPM moves also from 0.8 to -0.6.
The correlation coefficients between BACHY and the other financial institutions become generally positive but do not exceed 0.6.
In a similar way, the correlation coefficients between MUFG and the other financial institutions are rather higher but do not exceed 0.6 except the 0.8 correlation coefficient with ING.